home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / FLAT.ZIP / FLATFILE.C < prev    next >
C/C++ Source or Header  |  1993-06-19  |  3KB  |  133 lines

  1. #define WIN31
  2. #include <windows.h>
  3. /* For the fancy looking Borland dialog box routines */
  4. #ifdef USES_BWCC
  5. #include <bwcc.h>
  6. #endif
  7. #include "flatm.h"
  8. #pragma hdrstop
  9. #include <io.h>
  10. #include "flatfile.h"
  11. #include "flatdata.h"
  12.  
  13. #ifdef USES_MEMCHECK
  14. /* Memory checking routines  by StratosWare Corp. */
  15. #include "\wmemchec\memcheck.h"
  16. #endif
  17.  
  18. /*--------------------------------------------
  19. -
  20. -       FLATFILE.C For Flat Windows Program
  21. -
  22. -            Date file routines for Flat
  23. -
  24. -               Dennis R. Fischer
  25. -                 Denam Systems
  26. -          1115 Madison St. NE  Suite 226
  27. -              Salem, Oregon  97303
  28. -
  29. -             CompuServe 70405,1422
  30. -        Internet 70405.1422@compuserve.com
  31. -
  32. -        Developed with Borland 3.1 Compiler
  33. -
  34. -     Free for the taking but please give credit
  35. -                where credit is do
  36. -
  37. ----------------------------------------------*/              
  38.  
  39.  
  40. char flatfilename[] = {"flat.sav"};
  41.  
  42. long GetNumOfFlatRecords(void)
  43. {
  44.     /* Get the total number of records in the data base */
  45.     long  lTotRecs=0L;
  46.     long  lFileSize;
  47.     HFILE fhand;
  48.  
  49.     fhand = _lopen(flatfilename, OF_READ);
  50.   if (fhand != -1 ) {
  51.         /* File was found */
  52.     lFileSize = _llseek(fhand, 0L, SEEK_END);
  53.         if (lFileSize > 0L) {
  54.         lTotRecs = lFileSize / (long)sizeof(struct tagFLATDATA);
  55.     }
  56.     _lclose(fhand);
  57.   }
  58.   return lTotRecs;
  59. }
  60.  
  61. BOOL readdatafile (long recnum)
  62. {
  63.     /* Read one record in the data base */
  64.   BOOL               bGood = FALSE;
  65.     HFILE              fhand;
  66.     int                recsize;
  67.     long               result;
  68.   struct tagFLATDATA Flat;
  69.  
  70.   recsize = sizeof(Flat);
  71.   fhand = _lopen(flatfilename, OF_READ);
  72.   if (fhand != -1 ) {
  73.         /* File was found */
  74.     result = _llseek(fhand, recnum * recsize, SEEK_SET);
  75.     if (result != -1L) {
  76.       if (_lread(fhand, (LPSTR)&Flat, (WORD)recsize) == recsize){
  77.                 bGood = TRUE;
  78.         SetFlatData(&Flat);
  79.       }
  80.     }
  81.     _lclose(fhand);
  82.   }
  83.   return bGood;
  84. }  /* readdatafile */
  85.  
  86. BOOL savedatafile (long recnum)
  87. {
  88.     /* Save a record in the data base */
  89.   HFILE              fhand;
  90.   struct tagFLATDATA Flat;
  91.     long               tl;
  92.   BOOL               bGood = FALSE;
  93.     int                recsize;
  94.  
  95.   recsize = (WORD)sizeof(Flat);
  96.     fhand = _lopen(flatfilename, OF_READWRITE);
  97.   if (fhand != -1 ) {
  98.         /* File was found */
  99.     GetFlatData(&Flat);
  100.         tl = _llseek(fhand, recnum * recsize, 0);
  101.         if (tl != HFILE_ERROR){
  102.             _lwrite(fhand, (LPSTR)&Flat, recsize);
  103.             bGood = TRUE;
  104.     }
  105.     _lclose(fhand);
  106.     }
  107.   return bGood;
  108. }  /* savedatafile */
  109.  
  110. BOOL SaveNewSale (void)
  111. {
  112.     /* Save a new record in the data base. Create the
  113.          data base file if needed
  114.     */
  115.   HFILE fhand2;
  116.     BOOL bGood=FALSE;
  117.   struct tagFLATDATA Flat;
  118.  
  119.     fhand2 = _lopen(flatfilename, OF_READWRITE);
  120.   if (fhand2 == -1)
  121.     /* Try to create it */
  122.         fhand2 = _lcreat(flatfilename, 0);
  123.   if (fhand2 != -1 ) {
  124.     /* File was found so move to end of file */
  125.         _llseek(fhand2, 0L, SEEK_END);
  126.         GetFlatData(&Flat);
  127.         Flat.Used = TRUE;
  128.         _lwrite(fhand2, &Flat, (UINT)sizeof(Flat));
  129.     _lclose(fhand2);
  130.     bGood = TRUE;
  131.   }
  132.   return bGood;
  133. }  /* SaveNewSale */